package linter.linterjava.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageInfo;
import linter.linterjava.POJO.DO.Curriculum;
import linter.linterjava.POJO.DO.CurriculumPlan;
import linter.linterjava.POJO.DTO.CurriculumDTO;
import linter.linterjava.POJO.DTO.CurriculumPlanDTO;
import linter.linterjava.POJO.UtilDTO.PageInfoDTO;
import linter.linterjava.service.CurriculumService;
import linter.linterjava.mapper.CurriculumMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


import static linter.linterjava.custom.ConstantPublicWay.getPageInfo;

/**
* @author 北煜
* @description 针对表【curriculum(课程详情表)】的数据库操作Service实现
* @createDate 2024-07-07 12:15:15
*/
@Service
public class CurriculumServiceImpl extends ServiceImpl<CurriculumMapper, Curriculum>
    implements CurriculumService{

    @Resource
    CurriculumMapper curriculumMapper;

    @Override
    public List<Curriculum> queryCurriculum(CurriculumDTO curriculumDTO, Long uuid) {
        QueryWrapper<Curriculum> queryWrapper = new QueryWrapper<>();
        if (curriculumDTO.getCurriculumName() != null && !"".equals(curriculumDTO.getCurriculumName())){
            queryWrapper.like("curriculum_name","%"+curriculumDTO.getCurriculumName()+"%").eq("is_delete",0);
        } else if (curriculumDTO.getCurriculumNode()!=null && !"".equals(curriculumDTO.getCurriculumNode())){
            queryWrapper.like("curriculum_node","%"+curriculumDTO.getCurriculumNode()+"%").eq("is_delete",0);
        }else if (curriculumDTO.getCurriculumType()!=null && !"".equals(curriculumDTO.getCurriculumType())){
            queryWrapper.like("curriculum_type","%"+curriculumDTO.getCurriculumType()+"%").eq("is_delete",0);
        }
        return curriculumMapper.selectList(queryWrapper);
    }

    @Override
    public PageInfo<Curriculum> getAllCurriculumByType(CurriculumDTO curriculumDTO, Long uuid) {
        PageInfoDTO pageInfoDTO = new PageInfoDTO();
        pageInfoDTO.setPageNum(curriculumDTO.getPageNum());
        pageInfoDTO.setPageSize(curriculumDTO.getPageSize());
        return getPageInfo(pageInfoDTO, new QueryWrapper<Curriculum>()
                .eq("is_delete",0).eq("curriculum_type", curriculumDTO.getCurriculumType()), curriculumMapper);
    }

    @Override
    public Curriculum getCurriculumById(CurriculumDTO curriculumDTO, Long uuid) {
        return curriculumMapper.selectOne(new QueryWrapper<Curriculum>()
                .eq("id",curriculumDTO.getId()).eq("is_delete",0));
    }

    @Override
    public PageInfo<Curriculum> getCurriculumBase(PageInfoDTO pageInfoDTO, Long uuid) {
        return getPageInfo(pageInfoDTO, new QueryWrapper<Curriculum>().eq("curriculum_node",1).eq("is_delete",0),
                curriculumMapper);
    }


}




